import Blender
from Blender import *
from Blender.Scene import Render

import sys, os

DIR = 'data'
LOG = 'samples'

scn = Scene.GetCurrent()
context = scn.getRenderingContext()
context.setRenderer(Render.INTERNAL)
context.enableRayTracing(0)
context.setImageType(Render.PNG)

cam = Blender.Object.Get('Camera')

x1, y1, z1 = cam.getLocation()

# Change the camera position.
#cam.setLocation(x1 + float(sys.argv[7]), y1 + float(sys.argv[8]), z1 + float(sys.argv[9]))
cam.setLocation(x1 + float(sys.argv[7]), y1 + float(sys.argv[8]), z1)
# Change the camera orientation.
#cam.RotX += float(sys.argv[10])
#cam.RotY += float(sys.argv[11])
cam.RotZ += float(sys.argv[12])

x1, y1, z1 = cam.getLocation()
rotx, roty, rotz = cam.loc

cube = Blender.Object.Get('Cube')
x2, y2, z2 = cube.getLocation()

#d = [x2 - x1, y2 - y1, z2 - z1]
d = [x2 - x1, y2 - y1]

f = open(os.path.join(DIR, LOG), 'a')
#f.write(str(d[0]) + ',' + str(d[1]) + ',' + str(d[2]) + ':' + str(cam.RotX) + ',' + str(cam.RotY) + ',' + str(cam.RotZ) + '\n')
f.write(str(d[0]) + ',' + str(d[1]) + ':' + str(cam.RotZ) + '\n')
f.close()
